package com.example.singlelimitdemo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String handleException(Exception e) {
        log.error("系统内部异常", e);
        return "系统内部异常";
    }


    @ExceptionHandler(value = LimitAccessException.class)
    public String handleLimitAccessException(LimitAccessException e){
        log.error("触发LimitAccessException异常",e);
        return e.getMessage();
    }

}
